/**
 * 
 */
package com.gmail.blackdog1987.onedollar.web.controller;

import com.gmail.blackdog1987.onedollar.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 
 * @author 董国超
 *
 */
@Controller
public class GoodsController extends BaseController {
	@Autowired
	private GoodsService goodsService;

	/**
	 * 获取一元购列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getOneDollarList", method=RequestMethod.POST)
	public Map<String, Object> getOneDollarList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getOneDollarList(filter, 1);
		return decorateResult(result);
	}

	/**
	 * 获取一元购列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getMyOneDollarList", method=RequestMethod.POST)
	public Map<String, Object> getMyOneDollarList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		System.out.println("xxxxxxxxxxxxxxxx\n"+filter.toString());
		Map<String, Object> result = goodsService.getMyOneDollarList(filter, 1);
		return decorateResult(result);
	}

	/**
	 * 获取往期一元十元
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getOneDollarHistory", method=RequestMethod.POST)
	public Map<String, Object> getOneDollarHistory(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getOneDollarHistory(filter);
		return decorateResult(result);
	}

	/**
	 * 一元购详情
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getOneDollarDetail", method=RequestMethod.POST)
	public Map<String, Object> getOneDollarDetail(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getOneDollarDetail(filter);
		return decorateResult(result);
	}

	/**
	 * 一元购中奖人查询
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getOneDollarWinner", method=RequestMethod.POST)
	public Map<String, Object> getOneDollarWinner(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getOneDollarWinner(filter);
		return decorateResult(result);
	}

	/**
	 * 十元购列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getTenDollarList", method=RequestMethod.POST)
	public Map<String, Object> getTenDollarList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getOneDollarList(filter, 10);
		return decorateResult(result);
	}

	/**
	 * 最新揭晓
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getNewOneDollarList", method=RequestMethod.POST)
	public Map<String, Object> getNewOneDollarList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getNewOneDollarList(filter);
		return decorateResult(result);
	}

	/**
	 * 即将揭晓
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getPresentOneDollarList", method=RequestMethod.POST)
	public Map<String, Object> getPresentOneDollarList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getPresentOneDollarList(filter);
		return decorateResult(result);
	}

	/**
	 * 十元购列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getMyTenDollarList", method=RequestMethod.POST)
	public Map<String, Object> getMyTenDollarList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getMyOneDollarList(filter, 10);
		return decorateResult(result);
	}

	/**
	 * 获取一元/十元获奖列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getOneDollarWin", method=RequestMethod.POST)
	public Map<String, Object> getOneDollarWin(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getOneDollarWin(filter);
		return decorateResult(result);
	}

	/**
	 * 晒单列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getGoodsShowList", method=RequestMethod.POST)
	public Map<String, Object> getGoodsShow(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getShowList(filter);
		return decorateResult(result);
	}

	/**
	 * 晒单详情
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getGoodsShowDetail", method=RequestMethod.POST)
	public Map<String, Object> getGoodsShowDetail(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getShow(filter);
		return decorateResult(result);
	}

	/**
	 * 添加晒单
	 * @param filter
	 * @param request
	 * @param response
	 * @return0
	 */
	@ResponseBody
	@RequestMapping(value="addShow", method=RequestMethod.POST)
	public Map<String, Object> addShow(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.doAddShow(filter);
		return decorateResult(result);
	}

	/**
	 * 添加晒单
	 * @param filter
	 * @param request
	 * @param response
	 * @return0
	 */
	@ResponseBody
	@RequestMapping(value="getKeywords", method=RequestMethod.POST)
	public Map<String, Object> getKeywords(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getKeywords(filter);
		return decorateResult(result);
	}

	/**
	 * 商城列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getGoodsList", method=RequestMethod.POST)
	public Map<String, Object> getGoodsList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getGoodsList(filter);
		return decorateResult(result);
	}

	/**
	 * 我的购买列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getMyGoodsList", method=RequestMethod.POST)
	public Map<String, Object> getMyGoodsList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getMyGoodsList(filter);
		return decorateResult(result);
	}

	/**
	 * 评论列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getCommentList", method=RequestMethod.POST)
	public Map<String, Object> getCommentList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getCommentList(filter);
		return decorateResult(result);
	}

	/**
	 * 商城详情
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getGoodsDetail", method=RequestMethod.POST)
	public Map<String, Object> getGoodsDetail(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getGoodsDetail(filter);
		return decorateResult(result);
	}

	/**
	 * 获取大分类
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getMainCat", method=RequestMethod.POST)
	public Map<String, Object> getMainCat(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getMainCat(filter);
		return decorateResult(result);
	}

	/**
	 * 获取小分类
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getCat", method=RequestMethod.POST)
	public Map<String, Object> getCat(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getCat(filter);
		return decorateResult(result);
	}

	/**
	 * 获取一元参加人列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getOneDollarJoin", method=RequestMethod.POST)
	public Map<String, Object> getOneDollarJoin(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getOneDollarJoin(filter);
		return decorateResult(result);
	}

	/**
	 * 新增晒单点赞
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showLike", method=RequestMethod.POST)
	public Map<String, Object> showLike(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.updateShowLike(filter);
		return decorateResult(result);
	}

	/**
	 * 新增晒单评论
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="showComment", method=RequestMethod.POST)
	public Map<String, Object> showComment(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.createShowComment(filter);
		return decorateResult(result);
	}

	/**
	 * 获取晒单评论列表
	 * @param filter
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="getShowCommentList", method=RequestMethod.POST)
	public Map<String, Object> getShowCommentList(@RequestParam Map<String, String> filter, HttpServletRequest request, HttpServletResponse response) {
		Map<String, Object> result = goodsService.getShowCommentList(filter);
		return decorateResult(result);
	}

	@Override
	protected Map<String, Object> decorateResult(Map<String, Object> result) {
		result.put("time", System.currentTimeMillis());
		return result;
	}
}
